#include "stdafx.h"
#include "SymbolInfo.h"
#include "p2.h"


CSymbolInfo::CSymbolInfo()
{
	for (int i = 0; i < 5; i++)
	{
		m_QuoteInfo.BuyQ[i].Quote = 0;
		m_QuoteInfo.BuyQ[i].QuoteCnt = 0;
		m_QuoteInfo.BuyQ[i].QuoteQty = 0;

		m_QuoteInfo.SellQ[i].Quote = 0;
		m_QuoteInfo.SellQ[i].QuoteCnt = 0;
		m_QuoteInfo.SellQ[i].QuoteQty = 0;
	}

	m_QuoteInfo.TotalBuyQuoteCnt = 0;
	m_QuoteInfo.TotalBuyQuoteQty = 0;
	m_QuoteInfo.TotalSellQouteQty = 0;
	m_QuoteInfo.TotalSellQuoteCnt = 0;

	m_PriceInfo.C = 0;
	m_PriceInfo.Change = 0;
	m_PriceInfo.H = 0;
	m_PriceInfo.L = 0;
	m_PriceInfo.O = 0;
	m_PriceInfo.V = 0;
}


CSymbolInfo::~CSymbolInfo()
{
}


void CSymbolInfo::AddTickInfo(lpExpTr0932O_sub a_Sub)
{
	size_t size = dqTickInfo.size();
	TickInfo curTick;

	string val;
	val.assign(a_Sub->CurrPrice, sizeof(a_Sub->CurrPrice));
	curTick.Price = _ttof(val.c_str());
	val.assign(a_Sub->Time, sizeof(a_Sub->Time));
	curTick.Time = _ttoi(val.c_str());
	COleDateTime t1 = COleDateTime::GetCurrentTime();
	curTick.oleTime = t1.Format(_T("%H:%M:%S"));
	val.assign(a_Sub->NowVol, sizeof(a_Sub->NowVol));
	curTick.Volume = _ttoi(val.c_str());
	val.assign(a_Sub->MatchKind, sizeof(a_Sub->MatchKind));
	if (val.compare(_T("+")) == 0)
		curTick.LSType = iptLong;
	else
		curTick.LSType = iptShort;

	if (size > 40)
	{
		// Remove the oldest item in the deque;
		dqTickInfo.pop_back();
		// Add the recent item on the deque;
		dqTickInfo.push_front(curTick);
	}
	else
	{
		// Just add the item on the deque;
		dqTickInfo.push_front(curTick);
	}
}

void CSymbolInfo::OnPriceChanged(lpExpTr2003O_st a_CurPrice)
{
	string val;
	val.assign(a_CurPrice->CurrPrice, sizeof(a_CurPrice->CurrPrice));
	m_PriceInfo.C = _ttof(val.c_str());
	val.assign(a_CurPrice->CmpPrice, sizeof(a_CurPrice->CmpPrice));
	m_PriceInfo.Change = _ttof(val.c_str());
	val.assign(a_CurPrice->Volume, sizeof(a_CurPrice->Volume));
	m_PriceInfo.V = _ttoi(val.c_str());
	val.assign(a_CurPrice->StartPrice, sizeof(a_CurPrice->StartPrice));
	m_PriceInfo.O = _ttof(val.c_str());
	val.assign(a_CurPrice->LowPrice, sizeof(a_CurPrice->LowPrice));
	m_PriceInfo.L = _ttof(val.c_str());
	val.assign(a_CurPrice->HighPrice, sizeof(a_CurPrice->HighPrice));
	m_PriceInfo.H = _ttof(val.c_str());
	val.assign(a_CurPrice->CmpRate, sizeof(a_CurPrice->CmpRate));
	m_PriceInfo.ChangeRate = _ttof(val.c_str());
	val.assign(a_CurPrice->PDEndPrice, sizeof(a_CurPrice->PDEndPrice));
	m_PriceInfo.PreClose = _ttof(val.c_str());
}

void CSymbolInfo::OnPriceChanged(lpExpTr0921O_st a_CurPrice)
{
	string val;
	val.assign(a_CurPrice->CurrPrice, sizeof(a_CurPrice->CurrPrice));
	m_PriceInfo.C = _ttof(val.c_str());
	val.assign(a_CurPrice->CmpPrice, sizeof(a_CurPrice->CmpPrice));
	m_PriceInfo.Change = _ttof(val.c_str());
	val.assign(a_CurPrice->Volume, sizeof(a_CurPrice->Volume));
	m_PriceInfo.V = _ttoi(val.c_str());
	val.assign(a_CurPrice->StartPrice, sizeof(a_CurPrice->StartPrice));
	m_PriceInfo.O = _ttof(val.c_str());
	val.assign(a_CurPrice->LowPrice, sizeof(a_CurPrice->LowPrice));
	m_PriceInfo.L = _ttof(val.c_str());
	val.assign(a_CurPrice->HighPrice, sizeof(a_CurPrice->HighPrice));
	m_PriceInfo.H = _ttof(val.c_str());
	val.assign(a_CurPrice->CmpRate, sizeof(a_CurPrice->CmpRate));
	m_PriceInfo.ChangeRate = _ttof(val.c_str());
	val.assign(a_CurPrice->PDEndPrice, sizeof(a_CurPrice->PDEndPrice));
	m_PriceInfo.PreClose = _ttof(val.c_str());
	string Time;
	Time.assign(a_CurPrice->Time, sizeof(a_CurPrice->Time));
	m_PriceInfo.ST = Time;
	m_PriceInfo.ET = Time;
}

void CSymbolInfo::OnQuoteChanged(lpExpTr2004O_st a_CurHoga)
{
	string val;
	for (int i = 0; i < 5; i++)
	{
		val.assign(a_CurHoga->arr[i].BuyPrice, sizeof(a_CurHoga->arr[i].BuyPrice));
		m_QuoteInfo.BuyQ[i].Quote = _ttof(val.c_str());
		val.assign(a_CurHoga->arr[i].SellPrice, sizeof(a_CurHoga->arr[i].SellPrice));
		m_QuoteInfo.SellQ[i].Quote = _ttof(val.c_str());

		val.assign(a_CurHoga->arr[i].BuyQty, sizeof(a_CurHoga->arr[i].BuyQty));
		m_QuoteInfo.BuyQ[i].QuoteQty = _ttoi(val.c_str());
		val.assign(a_CurHoga->arr[i].SellQty, sizeof(a_CurHoga->arr[i].SellQty));
		m_QuoteInfo.SellQ[i].QuoteQty = _ttoi(val.c_str());

		val.assign(a_CurHoga->arr[i].BuyCnt, sizeof(a_CurHoga->arr[i].BuyCnt));
		m_QuoteInfo.BuyQ[i].QuoteCnt = _ttoi(val.c_str());
		val.assign(a_CurHoga->arr[i].SellCnt, sizeof(a_CurHoga->arr[i].SellCnt));
		m_QuoteInfo.SellQ[i].QuoteCnt = _ttoi(val.c_str());
	}
	val.assign(a_CurHoga->SellTotQty, sizeof(a_CurHoga->SellTotQty));
	m_QuoteInfo.TotalSellQouteQty = _ttoi(val.c_str());

	val.assign(a_CurHoga->BuyTotQty, sizeof(a_CurHoga->BuyTotQty));
	m_QuoteInfo.TotalBuyQuoteQty = _ttoi(val.c_str());

	val.assign(a_CurHoga->SellCnt, sizeof(a_CurHoga->SellCnt));
	m_QuoteInfo.TotalSellQuoteCnt = _ttoi(val.c_str());

	val.assign(a_CurHoga->BuyCnt, sizeof(a_CurHoga->BuyCnt));
	m_QuoteInfo.TotalBuyQuoteCnt = _ttoi(val.c_str());
}

void CSymbolInfo::OnQuoteChanged(lpExpTr0923O_st a_CurHoga)
{
	string val;
	for (int i = 0; i < 5; i++)
	{
		val.assign(a_CurHoga->arr[i].BuyPrice, sizeof(a_CurHoga->arr[i].BuyPrice));
		m_QuoteInfo.BuyQ[i].Quote = _ttof(val.c_str());
		val.assign(a_CurHoga->arr[i].SellPrice, sizeof(a_CurHoga->arr[i].SellPrice));
		m_QuoteInfo.SellQ[i].Quote = _ttof(val.c_str());

		val.assign(a_CurHoga->arr[i].BuyQty, sizeof(a_CurHoga->arr[i].BuyQty));
		m_QuoteInfo.BuyQ[i].QuoteQty = _ttoi(val.c_str());
		val.assign(a_CurHoga->arr[i].SellQty, sizeof(a_CurHoga->arr[i].SellQty));
		m_QuoteInfo.SellQ[i].QuoteQty = _ttoi(val.c_str());

		val.assign(a_CurHoga->arr[i].BuyCnt, sizeof(a_CurHoga->arr[i].BuyCnt));
		m_QuoteInfo.BuyQ[i].QuoteCnt = _ttoi(val.c_str());
		val.assign(a_CurHoga->arr[i].SellCnt, sizeof(a_CurHoga->arr[i].SellCnt));
		m_QuoteInfo.SellQ[i].QuoteCnt = _ttoi(val.c_str());
	}
	val.assign(a_CurHoga->Time, sizeof(a_CurHoga->Time));
	m_QuoteInfo.Time = val;

	val.assign(a_CurHoga->SellTotQty, sizeof(a_CurHoga->SellTotQty));
	m_QuoteInfo.TotalSellQouteQty = _ttoi(val.c_str());

	val.assign(a_CurHoga->BuyTotQty, sizeof(a_CurHoga->BuyTotQty));
	m_QuoteInfo.TotalBuyQuoteQty = _ttoi(val.c_str());

	val.assign(a_CurHoga->SellCnt, sizeof(a_CurHoga->SellCnt));
	m_QuoteInfo.TotalSellQuoteCnt = _ttoi(val.c_str());

	val.assign(a_CurHoga->BuyCnt, sizeof(a_CurHoga->BuyCnt));
	m_QuoteInfo.TotalBuyQuoteCnt = _ttoi(val.c_str());
}

